/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * hostGui.java
 *
 * Created on Jul 14, 2010, 7:15:16 PM
 */

package gui;

import data.hostInfoStorage;
import data.runConfig;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import threads.commandThread;

/**
 *
 * @author Todd Bodnar
 */
public class hostGui extends javax.swing.JFrame {

    /** Creates new form hostGui */
    public hostGui() {
        startTime = System.currentTimeMillis();
        timedOut = 0;
        goPressCt = 0;
        totalTime = 0;
        totalData = 0;

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        decompressText = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        connectionPanel = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        timeOutTextField = new javax.swing.JTextField();
        timeOutCount = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        assignmentPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        completedList = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        toDoList = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        inProgressList = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        addProjectsButton = new javax.swing.JButton();
        loadButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        timeOutAllButton = new javax.swing.JButton();
        clearAllButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        progressPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        assignmentProgress = new javax.swing.JProgressBar();
        downloadProgress = new javax.swing.JProgressBar();
        jLabel3 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        finishedProgress = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        uploadProgress = new javax.swing.JProgressBar();
        jLabel4 = new javax.swing.JLabel();
        statsPanel = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        projectsPerHour = new javax.swing.JLabel();
        goPressPerSec = new javax.swing.JLabel();
        avgCompletionTime = new javax.swing.JLabel();
        dataGenerated = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel5.setText("Cluster Logo Server");

        jLabel6.setText(tools.version.SERVER_VERSION);

        decompressText.setText(" ");

        jLabel13.setText("Time Out (hours)");

        timeOutTextField.setText("24");

        timeOutCount.setText("0");

        jLabel14.setText("Projects Timed Out");

        try{
            jLabel12.setText("My IP: "+InetAddress.getLocalHost().getHostAddress());
        }catch(UnknownHostException e){JOptionPane.showMessageDialog(null,e);}

        javax.swing.GroupLayout connectionPanelLayout = new javax.swing.GroupLayout(connectionPanel);
        connectionPanel.setLayout(connectionPanelLayout);
        connectionPanelLayout.setHorizontalGroup(
            connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(connectionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(connectionPanelLayout.createSequentialGroup()
                        .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 299, Short.MAX_VALUE)
                        .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(timeOutCount)
                            .addComponent(timeOutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        connectionPanelLayout.setVerticalGroup(
            connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(connectionPanelLayout.createSequentialGroup()
                .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(timeOutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(timeOutCount)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Connection", connectionPanel);

        completedList.setColumns(20);
        completedList.setRows(5);
        jScrollPane2.setViewportView(completedList);

        jLabel9.setText("To Do");

        toDoList.setColumns(20);
        toDoList.setRows(5);
        jScrollPane1.setViewportView(toDoList);

        inProgressList.setColumns(20);
        inProgressList.setRows(5);
        jScrollPane3.setViewportView(inProgressList);

        jLabel10.setText("In Progress");

        jLabel11.setText("Completed");

        addProjectsButton.setText("Add Projects");
        addProjectsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addProjectsButtonActionPerformed(evt);
            }
        });

        loadButton.setText("Load Assignments");
        loadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadButtonActionPerformed(evt);
            }
        });

        saveButton.setText("Save Assignments");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        timeOutAllButton.setText("Time Out All");
        timeOutAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                timeOutAllButtonActionPerformed(evt);
            }
        });

        clearAllButton.setText("Delete All");
        clearAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearAllButtonActionPerformed(evt);
            }
        });

        deleteButton.setText("Delete Assignments");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout assignmentPanelLayout = new javax.swing.GroupLayout(assignmentPanel);
        assignmentPanel.setLayout(assignmentPanelLayout);
        assignmentPanelLayout.setHorizontalGroup(
            assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(assignmentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(saveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(timeOutAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(clearAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(loadButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(38, 38, 38)
                .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                    .addComponent(addProjectsButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        assignmentPanelLayout.setVerticalGroup(
            assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(assignmentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(assignmentPanelLayout.createSequentialGroup()
                        .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(assignmentPanelLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addGap(102, 102, 102)))
                        .addGap(18, 18, 18)
                        .addComponent(loadButton))
                    .addGroup(assignmentPanelLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(saveButton))
                    .addGroup(assignmentPanelLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(addProjectsButton)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(assignmentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(timeOutAllButton)
                    .addComponent(clearAllButton)
                    .addComponent(deleteButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Assignments", assignmentPanel);

        jLabel1.setText("Assignment");

        assignmentProgress.setString("0 / 0");
        assignmentProgress.setStringPainted(true);

        downloadProgress.setString("inactive");
        downloadProgress.setStringPainted(true);

        jLabel3.setText("Current Upload");

        finishedProgress.setString("0 / 0");
        finishedProgress.setStringPainted(true);

        jLabel2.setText("Finished");

        uploadProgress.setString("inactive");
        uploadProgress.setStringPainted(true);

        jLabel4.setText("Current Download");

        javax.swing.GroupLayout progressPanelLayout = new javax.swing.GroupLayout(progressPanel);
        progressPanel.setLayout(progressPanelLayout);
        progressPanelLayout.setHorizontalGroup(
            progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(progressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(progressPanelLayout.createSequentialGroup()
                        .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                        .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(finishedProgress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(assignmentProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
                    .addGroup(progressPanelLayout.createSequentialGroup()
                        .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 83, Short.MAX_VALUE)
                        .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(downloadProgress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(uploadProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        progressPanelLayout.setVerticalGroup(
            progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(progressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(assignmentProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(finishedProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(uploadProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(downloadProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(86, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Progress", progressPanel);

        jLabel18.setText("Projects / Hour");

        jLabel19.setText("Data Generated");

        jLabel16.setText("\"Go\" Presses / Second");

        jLabel17.setText("Average Completion Time");

        projectsPerHour.setText("0");

        goPressPerSec.setText("0");

        avgCompletionTime.setText("0");

        dataGenerated.setText("0 Bytes");

        javax.swing.GroupLayout statsPanelLayout = new javax.swing.GroupLayout(statsPanel);
        statsPanel.setLayout(statsPanelLayout);
        statsPanelLayout.setHorizontalGroup(
            statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(statsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 318, Short.MAX_VALUE)
                        .addComponent(goPressPerSec))
                    .addGroup(statsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 302, Short.MAX_VALUE)
                        .addComponent(avgCompletionTime))
                    .addGroup(statsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 352, Short.MAX_VALUE)
                        .addComponent(projectsPerHour))
                    .addGroup(statsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 317, Short.MAX_VALUE)
                        .addComponent(dataGenerated)))
                .addContainerGap())
        );
        statsPanelLayout.setVerticalGroup(
            statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statsPanelLayout.createSequentialGroup()
                .addContainerGap(123, Short.MAX_VALUE)
                .addGroup(statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(goPressPerSec))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(avgCompletionTime))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(projectsPerHour))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(dataGenerated))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Stats", statsPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 298, Short.MAX_VALUE)
                        .addComponent(decompressText, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(40, 40, 40))
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(decompressText))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addProjectsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addProjectsButtonActionPerformed
        assignmentMakerGUI gui = new assignmentMakerGUI(getDataStorage(), this);
        gui.setVisible(true);
    }//GEN-LAST:event_addProjectsButtonActionPerformed

    private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
        JFileChooser jfc = new JFileChooser();
        jfc.showOpenDialog(this);

        if(jfc.getSelectedFile()==null)
            return;
        try {
            Scanner in = new Scanner(new FileInputStream(jfc.getSelectedFile()));
            in.useDelimiter("\n");

            while(in.hasNext())
            {
                try
                {
                    getDataStorage().addTodo(new runConfig(in.next()));
                }
                catch (Exception ex)
                {
                    //Logger.getLogger(hostGui.class.getName()).log(Level.WARNING, null, ex);
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(hostGui.class.getName()).log(Level.SEVERE, null, ex);
        }

        updateView();

    }//GEN-LAST:event_loadButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        JFileChooser jfc = new JFileChooser();
        jfc.showSaveDialog(this);

        if(jfc.getSelectedFile()==null)
            return;
        try {
            PrintStream out = new PrintStream(new FileOutputStream(jfc.getSelectedFile()));
            out.print(getDataStorage().describeTodo());
            out.flush();
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(hostGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void timeOutAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeOutAllButtonActionPerformed

        while(storage.getAssigned()>0)
        {
            storage.timeOut(storage.getAssignedProject());
            this.incrementTimeOutCt();
        }

        this.updateView();
    }//GEN-LAST:event_timeOutAllButtonActionPerformed

    private void clearAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearAllButtonActionPerformed
        storage.removeAll();
        updateView();
    }//GEN-LAST:event_clearAllButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        new removerGUI(storage).setVisible(true);
    }//GEN-LAST:event_deleteButtonActionPerformed

    /**
     * Tests hostGui
     *
    * @param args the command line arguments
    */
    public static void main(String args[]) throws IOException {
           hostGui gui = new hostGui();
           gui.setVisible(true);
           gui.setDataStorage(new hostInfoStorage());
           Thread t = new Thread(new commandThread(gui.storage, gui));
           t.start();
           Vector<String> v = new Vector();
           v.add("test1 15");
           v.add("test2 54");
           gui.getDataStorage().addTodo(new runConfig(new File("testLogo.nLogo"),"someFile.dat",10000,v));
           gui.updateView();

    }

    public void setDataStorage(hostInfoStorage storage)
    {
        this.storage = storage;
    }

    public float getTimeOutRate()
    {
        return Float.parseFloat(timeOutTextField.getText());
    }

    public void setDecompressMessage(String txt)
    {
        decompressText.setText(txt);
    }

    public hostInfoStorage getDataStorage()
    {
        return storage;
    }

    public void updateView()
    {
        toDoList.setText(storage.describeTodo());
        inProgressList.setText(storage.describeInProgress());
        completedList.setText(storage.describeCompleted());

        if(storage.getTotal()>0)
        {
            assignmentProgress.setString(storage.getAssigned()+" / "+storage.getTotal());
            assignmentProgress.setMaximum(storage.getTotal());
            assignmentProgress.setValue(storage.getAssigned());

            finishedProgress.setString(storage.getCompleted()+" / "+storage.getTotal());
            finishedProgress.setMaximum(storage.getTotal());
            finishedProgress.setValue(storage.getCompleted());
        }
    }

    public JProgressBar getUploadBar()
    {
        return uploadProgress;
    }

    public JProgressBar getDownloadBar()
    {
        return downloadProgress;
    }

    /**
     * Updates goPressPerSecond
     * @param goes The number of aditional "go" presses
     */
    public void updateGoPress(long goes)
    {
        goPressCt+=goes;
        long time = (System.currentTimeMillis()-startTime)/1000;
        goPressPerSec.setText(""+1.0f*goPressCt/time);
    }

    /**
     * Updates the averageCompletionTime label
     * @param newElement the number of milliseconds it took to complete an assignment
     */
    public void updateAverageCompletionTime(long newElement)
    {
        totalTime += newElement;
        double time = totalTime/1000/storage.getCompleted();
        String label = " seconds";
        if(time>60)
        {
            label = " minutes";
            time/=60;
        }
        if(time>60)
        {
            label = " hours";
            time/=60;
        }
        if(time>24)
        {
            label = " days";
            time/=24;
        }
        avgCompletionTime.setText(time+label);
    }

    /**
     * Updates the projectsPerHour label
     */
    public void updateProjectsPerHour()
    {
        projectsPerHour.setText(""+(storage.getCompleted())/((1.0*System.currentTimeMillis()-startTime)/1000/60/60));
    }

    public void incrementTimeOutCt()
    {
        timedOut++;
        timeOutCount.setText(""+timedOut);
    }

    /**
     * Updates the dataGenerated label
     * @param newDataLength the length, in bytes, of a result
     */
    public void updateDataGenerated(long newDataLength)
    {
        totalData += newDataLength;
        double temp = totalData;
        String label = " bytes";
        if(temp>1024)
        {
            label = " kilobytes";
            temp/=1024;
        }
        if(temp>1024)
        {
            label = " megabytes";
            temp/=1024;
        }
        if(temp>1024)
        {
            label = " gigabytes";
            temp/=1024;
        }
        if(temp>1024)
        {
            label = " terabytes";
            temp/=1024;
        }
        dataGenerated.setText(temp+label);
    }

    private hostInfoStorage storage;
    private long startTime, goPressCt, totalTime, totalData, timedOut;



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addProjectsButton;
    private javax.swing.JPanel assignmentPanel;
    private javax.swing.JProgressBar assignmentProgress;
    private javax.swing.JLabel avgCompletionTime;
    private javax.swing.JButton clearAllButton;
    private javax.swing.JTextArea completedList;
    private javax.swing.JPanel connectionPanel;
    private javax.swing.JLabel dataGenerated;
    private javax.swing.JLabel decompressText;
    private javax.swing.JButton deleteButton;
    private javax.swing.JProgressBar downloadProgress;
    private javax.swing.JProgressBar finishedProgress;
    private javax.swing.JLabel goPressPerSec;
    private javax.swing.JTextArea inProgressList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton loadButton;
    private javax.swing.JPanel progressPanel;
    private javax.swing.JLabel projectsPerHour;
    private javax.swing.JButton saveButton;
    private javax.swing.JPanel statsPanel;
    private javax.swing.JButton timeOutAllButton;
    private javax.swing.JLabel timeOutCount;
    private javax.swing.JTextField timeOutTextField;
    private javax.swing.JTextArea toDoList;
    private javax.swing.JProgressBar uploadProgress;
    // End of variables declaration//GEN-END:variables

}
